
define([
    "jquery",
    "IO",
    "bootbox"
], function ($, IO, bootbox) {

        var year_1=1;
        var year_2=2;
        var year_3=3;

    var activity_mid=$("#activity_mid_hidden").val();

    $("#btnSave1").click(function(){
        submit(1);
    });
    $("#btnSave2").click(function(){
        submit(2);
    });
    $("#btnSave3").click(function(){
        submit(3);
    });

    function submit(year_id){
        var id;
        if(year_id==1){
            id=0;
        }
        else if(year_id==2)
        {
            id=1;
        }
        else {
            id=2;
        }
        var redflag_count1=$(".row-1-input").eq(id).val()==""?"0":$(".row-1-input").eq(id).val();
        var redflag_count2=$(".row-2-input").eq(id).val()==""?"0":$(".row-2-input").eq(id).val();
        var redflag_count3=$(".row-3-input").eq(id).val()==""?"0":$(".row-3-input").eq(id).val();
        var redflag_count4=$(".row-4-input").eq(id).val()==""?"0":$(".row-4-input").eq(id).val();
        var redflag_count5=$(".row-5-input").eq(id).val()==""?"0":$(".row-5-input").eq(id).val();
        var redflag_count6=$(".row-6-input").eq(id).val()==""?"0":$(".row-6-input").eq(id).val();

        var group_mid1=$(".row-1-input").eq(id).attr("data-mid");
        var group_mid2=$(".row-2-input").eq(id).attr("data-mid");
        var group_mid3=$(".row-3-input").eq(id).attr("data-mid");
        var group_mid4=$(".row-4-input").eq(id).attr("data-mid");
        var group_mid5=$(".row-5-input").eq(id).attr("data-mid");
        var group_mid6=$(".row-6-input").eq(id).attr("data-mid");

        if(isNaN(redflag_count1)||isNaN(redflag_count2)||isNaN(redflag_count3)||isNaN(redflag_count4)||isNaN(redflag_count5)||isNaN(redflag_count6)){
            alert("请输入数字");
            return;
        }
        var params={};
        var isLast=false;

        if(activity_mid!="") {

            if(redflag_count2!=""&&redflag_count1!=""&&redflag_count3!=""&&redflag_count4!=""&&redflag_count5!=""&&redflag_count6!="") {

                for (var i = 1; i <= 6; i++) {
                    if(i==1){
                        params.group_mid=group_mid1;
                        params.redflag_count=redflag_count1;
                    }
                    else if(i==2){
                        params.group_mid=group_mid2;
                        params.redflag_count=redflag_count2;
                    }else if(i==3){
                        params.group_mid=group_mid3;
                        params.redflag_count=redflag_count3;
                    }
                    else if(i==4){
                        params.group_mid=group_mid4;
                        params.redflag_count=redflag_count4;
                    }
                    else if(i==5){
                        params.group_mid=group_mid5;
                        params.redflag_count=redflag_count5;
                    }
                    else if(i==6){
                        params.group_mid=group_mid6;
                        params.redflag_count=redflag_count6;
                        isLast=true;
                    }
                    params.year_id=year_id;

                    var j=1;
                    IO.post("/shapan/api/teamCombatCapability",params,function(d){

                        if(j==6){
                            alert(d.msg);
                        }
                        j++;
                    })
                }
            }
            else{
                alert("请填写完整!!!");
            }
        }
        else {
            alert("请创建活动");
        }

    }

});